package com.example.myapplication;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class Fragment2 extends Fragment {

    private RecyclerView recyclerView;
    private Fragment2_MyAdapter adapter;
    private List<Contact> contactList;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_2, container, false);

        recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        // 初始化联系人数据
        contactList = new ArrayList<>();
        contactList.add(new Contact("Alice", R.drawable.a)); // 确保提供头像资源
        contactList.add(new Contact("Bob", R.drawable.yayu));
        contactList.add(new Contact("Charlie", R.drawable.lifu));
        // 添加更多联系人...

        adapter = new Fragment2_MyAdapter(contactList);
        recyclerView.setAdapter(adapter);

        return view;
    }
}

/*
package com.example.myapplication;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

public class Fragment2 extends Fragment {

    private RecyclerView recyclerView;
    private Fragment2_MyAdapter adapter;
    private List<Contact> contactList;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_2, container, false);

        recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));

        // 初始化联系人数据
        contactList = new ArrayList<>();
        contactList.add(new Contact("白毛", R.drawable.a)); // 确保提供头像资源
        contactList.add(new Contact("忘记什么名字", R.drawable.suxin));
        contactList.add(new Contact("小露", R.drawable.yayu));
        contactList.add(new Contact("骡子姐", R.drawable.luosaita));
        contactList.add(new Contact("土木学姐", R.drawable.kalienina));
        contactList.add(new Contact("娜娜米", R.drawable.qishi));
        contactList.add(new Contact("火子哥", R.drawable.li));
        contactList.add(new Contact("小天使", R.drawable.lifu));
        // 添加更多联系人...

        adapter = new Fragment2_MyAdapter(getContext(), contactList); // 传递上下文
        recyclerView.setAdapter(adapter);

        return view;
    }
}
*/

